// 使用TS的属性装饰器创建随机色块
const RandomColorDecorator: PropertyDecorator = (target: Object, propertyKey: string | symbol) => {
  const colors: string[] = ['tomato', 'skyblue', 'green', '#666666', '#333333']

  Object.defineProperty(target, propertyKey, {
    get() {
      return colors[~~(Math.random() * colors.length)]
    }
  })
}

class RandomColor {
  @RandomColorDecorator
  color: string | undefined

  public draw() {
    document.body.insertAdjacentHTML("beforeend",
      `<div style="height:200px;width:200px;background-color:${this.color}">coderzrf</div>`
    )
  }
}

new RandomColor().draw()
